﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace Gui.Functies.Takenlijst_popups
{
    public partial class Addtaak : Form
    {
        string naam;
        string status;
        int projectID;

        public Addtaak()
        {

        }

        public Addtaak(int projectnummer)
        {
            projectID = projectnummer;
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            naam = textBox1.Text;
            status = comboBox1.SelectedItem.ToString();

            if (naam != "" && status != "")
            {
                saveTask();
            }
            else
            {
                MessageBox.Show("Niet alle velden zijn ingevuld!");
            }
        }

        //ProjectID is nog een placeholder omdat de takenlijst nog bij de rest moet worden samengevoegd

        public void saveTask()
        {
            MySqlConnection grabConnection = new MySqlConnection("Server=qq-design.com;Port=3306;Database=cookicom0;Uid=cookicom0;pwd=pizzahut91");
            MySqlCommand taken = new MySqlCommand("INSERT INTO taken (TaakID, Taak, ProjectID, Status)" + "VALUES ('','"+naam+"','"+projectID+"','"+status+"')", grabConnection);

            try
            {
                grabConnection.Open();
                taken.ExecuteNonQuery();
            }
            catch (MySqlException e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
               grabConnection.Close();
               MessageBox.Show("Taak succesvol opgeslagen!");
               this.Close();
            }
        }

        private void Addtaak_Load(object sender, EventArgs e)
        {

        }
    }
}
